﻿using System.Configuration;

namespace SimpleMvcCaptcha.Utils
{
    internal static class Config
    {
        /// <summary>
        /// Maximum number for captcha's expression operands
        /// </summary>
        public static int MaxNumber
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaMaxNumber"]))
                    return 10;

                return int.Parse(ConfigurationManager.AppSettings["SimpleCaptchaMaxNumber"]);
            }
        }

        /// <summary>
        /// Text to substitute "+" operation
        /// </summary>
        public static string PlusOperationText
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaPlusOperationText"]))
                    return "plus";

                return ConfigurationManager.AppSettings["SimpleCaptchaPlusOperationText"];
            }
        }

        /// <summary>
        /// Text to substitute "-" operation
        /// </summary>
        public static string MinusOperationText
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaMinusOperationText"]))
                    return "minus";

                return ConfigurationManager.AppSettings["SimpleCaptchaMinusOperationText"];
            }
        }

        /// <summary>
        /// Name of controller to get image
        /// </summary>
        public static string CaptchaController
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaCaptchaController"]))
                    return "Captcha";

                return ConfigurationManager.AppSettings["SimpleCaptchaCaptchaController"];
            }
        }

        /// <summary>
        /// Name of action to get image
        /// </summary>
        public static string CaptchaAction
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaCaptchaAction"]))
                    return "GetImage";

                return ConfigurationManager.AppSettings["SimpleCaptchaCaptchaAction"];
            }
        }

        /// <summary>
        /// Secret key for string encription
        /// </summary>
        public static string SecretKey
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaSecretKey"]))
                    return "123456";

                return ConfigurationManager.AppSettings["SimpleCaptchaSecretKey"];
            }
        }

        /// <summary>
        /// Salt for encription
        /// </summary>
        public static string Salt
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaSalt"]))
                    return "12345678";

                return ConfigurationManager.AppSettings["SimpleCaptchaSalt"];
            }
        }

        /// <summary>
        /// Max amount of captcha's random lines
        /// </summary>
        public static int MaxRandomLines
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaMaxRandomLines"]))
                    return 5;

                return int.Parse(ConfigurationManager.AppSettings["SimpleCaptchaMaxRandomLines"]);
            }
        }

        /// <summary>
        /// Captcha's image width
        /// </summary>
        public static int Width
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaWidth"]))
                    return 100;

                return int.Parse(ConfigurationManager.AppSettings["SimpleCaptchaWidth"]);
            }
        }

        /// <summary>
        /// Captcha's image height
        /// </summary>
        public static int Height
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaHeight"]))
                    return 20;

                return int.Parse(ConfigurationManager.AppSettings["SimpleCaptchaHeight"]);
            }
        }

        /// <summary>
        /// Captcha's expression font name
        /// </summary>
        public static string FontName
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaFontName"]))
                    return "Times New Roman";

                return ConfigurationManager.AppSettings["SimpleCaptchaFontName"];
            }
        }

        /// <summary>
        /// Captcha's expression font size
        /// </summary>
        public static int FontSize
        {
            get
            {
                if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleCaptchaFontSize"]))
                    return 14;

                return int.Parse(ConfigurationManager.AppSettings["SimpleCaptchaFontSize"]);
            }
        }
    }
}
